<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit - Firmware API: USB</title>
<link href="mt_doxygen.css" rel="stylesheet" type="text/css" />
<link href="../resources/mt_doxytabs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.header {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12pt;
	color: #222222;
}
-->
</style>
</head>

<body>
<table width="800" border="0">
    <tr>
      <td colspan="3">
        <form method="get" action="http://www.google.com/search">
          <div align="right">
            <input type="text"   name="q" size="25"
              maxlength="255" value="" />
            <input type="submit" value="Search" />
            <input type="hidden" name="sitesearch" value="makingthings.com/ref/firmware/html" />
          </div>
        </form>
       </td>
    </tr>
    <tr>
      <td><div align="center"><a href="http://www.makingthings.com">
				<img src="../resources/logo_brown_medium.png" alt="MakingThings"
									width="200" height="78" border="0" align="middle" longdesc="http://www.makingthings.com" /></a></div></td>
				<td><div align="center" class="header">
      		Make Controller Kit <br />
          Firmware API
      </div></td>
      <td><div align="center"><a href="http://www.makezine.com">
					<img src="../resources/make_logo.png" alt="MAKE Zine" 
										width="164" height="73" border="0" align="middle" longdesc="http://www.makezine.com" /></a></div></td>
    </tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.5.4 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>USB<br>
<small>
[<a class="el" href="group___controller.html">Controller</a>]</small>
</h1>The USB subsystem provides access to USB Virtual Serial Port (CDC) functionality.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g76d8f65ff3616d070254b5d1d045034c">Usb_SetActive</a> (int state)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets whether the Usb subsystem is active.  <a href="#g76d8f65ff3616d070254b5d1d045034c"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g86fb085b1eace675a46d72e58c98fa09">Usb_GetActive</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read the active state of the Usb system.  <a href="#g86fb085b1eace675a46d72e58c98fa09"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g9e8e6bd516232a4ccc90a95cce74d5d0">Usb_Read</a> (char *buffer, int length)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read from the USB port.  <a href="#g9e8e6bd516232a4ccc90a95cce74d5d0"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g5e567d07fa00969777df67959d532ee5">Usb_Write</a> (char *buffer, int length)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Write to the USB port.  <a href="#g5e567d07fa00969777df67959d532ee5"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g83237266412f310be1779ff07110acdc">Usb_SlipSend</a> (char *buffer, int length)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Write to the USB port using SLIP codes to packetize messages.  <a href="#g83237266412f310be1779ff07110acdc"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___u_s_b.html#g9e3c83ebc7acfceda064b76c94c96d2a">Usb_SlipReceive</a> (char *buffer, int length)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read from the USB port using SLIP codes to de-packetize messages.  <a href="#g9e3c83ebc7acfceda064b76c94c96d2a"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The USB subsystem provides access to USB Virtual Serial Port (CDC) functionality. 
<p>
On OS X, the system USB CDC driver is used - no external drivers are needed. An entry in <b>/dev</b> is created - similar to <b>/dev/cu.usbmodem.xxxx</b>. It may be opened for reading and writing like a regular file using the standard POSIX open(), close(), read(), write() functions.<p>
On Windows, the first time the device is seen, it needs to be pointed to a .INF file containing additional information - the <b>make_controller_kit.inf</b> in the same directory as this file. Once Windows sets this up, the device can be opened as a normal COM port. See also the <b>mchelper</b> codebase for code snippets.<p>
<dl compact><dt><b><a class="el" href="todo.html#_todo000009">Todo:</a></b></dt><dd>expand usb support to include emulation of other kinds of USB device - mouse, keyboard, etc. </dd></dl>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="g86fb085b1eace675a46d72e58c98fa09"></a><!-- doxytag: member="usb.c::Usb_GetActive" ref="g86fb085b1eace675a46d72e58c98fa09" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_GetActive           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read the active state of the Usb system. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>State - 1 (on) or 0 (off). </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00107">107</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g9e8e6bd516232a4ccc90a95cce74d5d0"></a><!-- doxytag: member="usb.c::Usb_Read" ref="g9e8e6bd516232a4ccc90a95cce74d5d0" args="(char *buffer, int length)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_Read           </td>
          <td>(</td>
          <td class="paramtype">char *&nbsp;</td>
          <td class="paramname"> <em>buffer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>length</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read from the USB port. 
<p>
Pass in a pointer to a char buffer to read into, and the number of characters requested to read. This function will return immediately with the number of characters read. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>buffer</em>&nbsp;</td><td>A pointer to a char buffer to read into </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>length</em>&nbsp;</td><td>An integer specifying the number of characters to read </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The number of characters successfully read. </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00121">121</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g76d8f65ff3616d070254b5d1d045034c"></a><!-- doxytag: member="usb.c::Usb_SetActive" ref="g76d8f65ff3616d070254b5d1d045034c" args="(int state)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_SetActive           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>state</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets whether the Usb subsystem is active. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>state</em>&nbsp;</td><td>An integer specifying the active state of the Usb system - 1 (on) or 0 (off). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Zero on success. </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00076">76</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g9e3c83ebc7acfceda064b76c94c96d2a"></a><!-- doxytag: member="usb.c::Usb_SlipReceive" ref="g9e3c83ebc7acfceda064b76c94c96d2a" args="(char *buffer, int length)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_SlipReceive           </td>
          <td>(</td>
          <td class="paramtype">char *&nbsp;</td>
          <td class="paramname"> <em>buffer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>length</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read from the USB port using SLIP codes to de-packetize messages. 
<p>
SLIP (Serial Line Internet Protocol) is a way to separate one "packet" from another on an open serial connection. This is the way OSC messages are sent over USB, for example. SLIP uses a simple start/end byte and an escape byte in case your data actually contains the start/end byte. This function will block until it has received a complete SLIP encoded message, and will pass back the original message with the SLIP codes removed.<p>
Check the Wikipedia description of SLIP at <a href="http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol">http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol</a> <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>buffer</em>&nbsp;</td><td>A pointer to a char buffer to read into </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>length</em>&nbsp;</td><td>An integer specifying the number of characters to read </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The number of characters successfully written </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00246">246</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g83237266412f310be1779ff07110acdc"></a><!-- doxytag: member="usb.c::Usb_SlipSend" ref="g83237266412f310be1779ff07110acdc" args="(char *buffer, int length)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_SlipSend           </td>
          <td>(</td>
          <td class="paramtype">char *&nbsp;</td>
          <td class="paramname"> <em>buffer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>length</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Write to the USB port using SLIP codes to packetize messages. 
<p>
SLIP (Serial Line Internet Protocol) is a way to separate one "packet" from another on an open serial connection. This is the way OSC messages are sent over USB, for example. SLIP uses a simple start/end byte and an escape byte in case your data actually contains the start/end byte. Pass your normal buffer to this function to have the SLIP codes inserted and then write it out over USB.<p>
Check the Wikipedia description of SLIP at <a href="http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol">http://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol</a> <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>buffer</em>&nbsp;</td><td>A pointer to a char buffer to write from </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>length</em>&nbsp;</td><td>An integer specifying the number of characters to write </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The number of characters successfully written </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00194">194</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g5e567d07fa00969777df67959d532ee5"></a><!-- doxytag: member="usb.c::Usb_Write" ref="g5e567d07fa00969777df67959d532ee5" args="(char *buffer, int length)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Usb_Write           </td>
          <td>(</td>
          <td class="paramtype">char *&nbsp;</td>
          <td class="paramname"> <em>buffer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>length</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Write to the USB port. 
<p>
Pass in a pointer to a char buffer to from, and the number of characters requested to write. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>buffer</em>&nbsp;</td><td>A pointer to a char buffer to write from </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>length</em>&nbsp;</td><td>An integer specifying the number of characters to write </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The number of characters successfully written </dd></dl>

<p>Definition at line <a class="el" href="usb_8c-source.html#l00158">158</a> of file <a class="el" href="usb_8c-source.html">usb.c</a>.</p>

</div>
</div><p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit</title>
<style type="text/css">
<!--
.footer {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9pt;
	color: #999999;
}
-->
</style>
</head>

<body>
<hr size="1">
<div>
  <p class="footer">The Make Controller Kit is an open source project maintained by <a href="http://www.makingthings.com">MakingThings</a>.<br />
    MakingThings code is released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 license</a>.<br />
    Bug tracker, development wiki and status can be found at <a href="http://dev.makingthings.com">http://dev.makingthings.com</a>.<br />
		This document was last updated on 5 Dec 2007.
</p>
</div>
<!-- Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-769030-1";
urchinTracker();
</script>
</body>
</html>
